package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.common.utils.CollUtils;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.po.LearningLesson;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-03-27
 */
@Api(tags = "我的课程相关接口")
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {

    private final ILearningLessonService learningLessonService;

    @ApiOperation("分页查询我的课程")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> queryMyLessonPage(PageQuery page) {
        return learningLessonService.queryMyLessons(page);
    }
    @GetMapping("/now")
    @ApiOperation("查询当前正在学习的课程")
    public LearningLessonVO queryNowLearningLesson() {
        return learningLessonService.queryNowLearningLesson();
    }
    @DeleteMapping("/{courseId}")
    @ApiOperation("删除我的课程")
    public void deleteMyLesson(Long courseId) {
        Long userId = UserContext.getUser();
        learningLessonService.deleteUserLessons(userId, CollUtils.singletonList(courseId));
    }
    @GetMapping("{courseId}/valid")
    @ApiOperation("查询课程是否在有效期")
    Integer isLessonValid(@PathVariable("courseId") Long courseId){
        return learningLessonService.isLessonValid(courseId);
    }
    @GetMapping("/{courseId}")
    @ApiOperation("查询用户课表中指定课程状态")
    public LearningLessonVO queryLessonStatus(@PathVariable("courseId") Long courseId) {
        return learningLessonService.queryLessonStatus(courseId);
    }
    @GetMapping("{courseId}/count")
    @ApiOperation("统计课程学习人数")
    Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId){
        return learningLessonService.countLearningLessonByCourse(courseId);
    }
    @PostMapping("/plans")
    @ApiOperation("创建我的学习计划")
    private void createStudyPlans(@RequestBody LearningPlanDTO learningPlanDTO){
        learningLessonService.createStudyPlans(learningPlanDTO);
    }
    @GetMapping("/plans")
    @ApiOperation("查询我的学习计划进度")
    public LearningPlanPageVO queryMyLearningPlans(PageQuery query){

        return learningLessonService.queryMyLearningPlans(query);
    }

}
